package com.cskaoyan.listener;

import com.cskaoyan.config.SpringConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author stone
 * @date 2022/11/13 22:52
 */
public class ApplicationContextInitListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {

        ServletContext servletContext = sce.getServletContext();
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration.class);
        servletContext.setAttribute("applicationContext",applicationContext);

    }
}
